package com.qfedu.yanglao20admin.bayonet.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.entity.bayonet.BayonetManage;
import com.qfedu.yanglao20admin.bayonet.dao.BayonetManageDao;
import com.qfedu.yanglao20admin.bayonet.param.BayonetManageParam;
import com.qfedu.yanglao20admin.bayonet.service.BayonetManageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2023/5/5 20:18
 */
@Service
public class BayonetManageServiceImpl implements BayonetManageService {

    @Resource
    private BayonetManageDao bayonetManageDao;

    @Override
    public Page<BayonetManage> pageBayonetManage(BayonetManageParam param) {
        Integer offset = (param.getPageNum() - 1) * param.getPageSize();
        param.setOffset(offset);

        // 分页查询
        Page<BayonetManage> page = new Page<>(param.getPageNum(), param.getPageSize());
        List<BayonetManage> bayonetManages = bayonetManageDao.selectPage(param);


        // 页码
        page.setCurrent(param.getPageNum());
        page.setSize(param.getPageSize());

        // 总记录数
        Long aLong = bayonetManageDao.selectCount(null);
        page.setTotal(aLong);

        page.setRecords(bayonetManages);

        return page;
    }

    @Override
    public void deleteById(Integer id) {
        bayonetManageDao.deleteById(id);
    }

    @Override
    public void addBayonetManage(BayonetManage bayonetManage) {
        bayonetManageDao.insert(bayonetManage);
    }

    @Override
    public BayonetManage queryBayonetManage(Integer id) {
        return bayonetManageDao.selectById(id);
    }

    @Override
    public void updateBayonetManage(BayonetManage bayonetManage) {
        bayonetManageDao.updateById(bayonetManage);
    }

    @Override
    public List<BayonetManage> selectAllBayonet() {
        return bayonetManageDao.selectList(null);
    }
}
